import { powerTypeMap, deptTypeMap, originTypeMap, fixedAssetMap } from '@/config/dict'
import { byKeyGetItem } from '@/utils'
import { validPrice } from '@/utils/validate'
import { CustomStatus } from '@/components'

export const searchFormItem = (cascaderConfig) => {
  return [
    {
      type: 'input',
      key: 'keyword',
      label: '车牌号'
    },
    {
      type: 'cascader',
      key: 'accountList',
      label: '绑定人员',
      props: cascaderConfig,
      otherAttrs: {
        showAllLevels: false
      }
    },
    {
      type: 'select',
      key: 'status',
      label: '状态',
      options: deptTypeMap
    },
    {
      type: 'select',
      key: 'fixedAssets',
      label: '是否固定资产',
      labelWidth: '110px',
      options: fixedAssetMap
    }
  ]
}

export const tableColumn = (handleEdit, handleStart, handleDelete) => {
  return [
    {
      key: 'carNumber',
      label: '车牌号',
      minWidth: 120
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 120,
      render: (h, scope) => <CustomStatus list={deptTypeMap} value={scope.row.status} />
    },
    {
      key: 'bindAccountNames',
      label: '绑定人员',
      minWidth: 200
    },
    {
      key: 'orginType',
      label: '来源',
      minWidth: 120,
      render: (h, scope) => byKeyGetItem(originTypeMap, scope.row.orginType).value
    },
    {
      key: 'brand',
      label: '品牌',
      minWidth: 120
    },
    {
      key: 'carType',
      label: '车型',
      minWidth: 120
    },
    {
      key: 'powerType',
      label: '动力类型',
      minWidth: 120,
      render: (h, scope) => byKeyGetItem(powerTypeMap, scope.row.powerType).value
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '修改',
          authKey: 'd_3_2',
          click: handleEdit
        },
        {
          name: (scope) => scope.row.status === 1 ? '停用' : '开启',
          authKey: 'd_3_4',
          click: (id, row) => handleStart(id, row.status === 1 ? 2 : 1)
        },
        {
          name: '删除',
          authKey: 'd_3_3',
          confirm: '确认删除吗?',
          click: handleDelete
        }
      ]

    }
  ]
}

export const modalFormItem = (deviceDropList, accountCascadeList) => {
  return [
    {
      type: 'select',
      key: 'deviceIdList',
      label: '绑定设备',
      // required: true,
      slotAttrs: {
        options: deviceDropList,
        multiple: true,
        style: { width: '92%' }
      },
      col: 24
    },
    {
      type: 'cascader',
      key: 'accountIdList',
      label: '绑定人员',
      required: true,
      slotAttrs: {
        options: accountCascadeList,
        props: { multiple: true },
        showAllLevels: false,
        style: { width: '92%' }
      },
      col: 24
    },
    {
      type: 'radio',
      key: 'status',
      label: '状态',
      required: true,
      slotAttrs: {
        options: deptTypeMap
      },
      col: 12
    },
    {
      type: 'input',
      key: 'carNumber',
      label: '车牌号',
      required: true,
      col: 12
    },
    {
      type: 'input',
      key: 'carType',
      label: '车型',
      required: true,
      col: 12
    },
    {
      type: 'input',
      key: 'weight',
      label: '总质量',
      col: 12
    },
    {
      type: 'input',
      key: 'vin',
      label: '车架号',
      col: 12
    },
    {
      type: 'input',
      key: 'engineNo',
      label: '发动机号',
      col: 12
    },
    {
      type: 'input',
      key: 'brand',
      label: '品牌',
      col: 12
    },
    {
      type: 'date',
      key: 'productionDate',
      label: '生产日期',
      col: 12
    },
    {
      type: 'select',
      key: 'orginType',
      label: '来源',
      slotAttrs: {
        options: originTypeMap
      },
      col: 12
    },
    {
      type: 'select',
      key: 'powerType',
      label: '动力类型',
      slotAttrs: {
        options: powerTypeMap
      },
      col: 12
    },
    {
      type: 'input',
      key: 'insuranceCompany',
      label: '保险公司',
      col: 12
    },
    {
      type: 'date',
      key: 'insuranceExpireDate',
      label: '保险到期时间',
      col: 12
    },
    {
      type: 'input',
      key: 'price',
      label: '价值(元)',
      slotAttrs: {
        type: 'number'
      },
      rules: [
        { validator: validPrice, trigger: 'blur' }
      ],
      col: 12
    },
    {
      type: 'input',
      key: 'ownership',
      label: '所有权',
      col: 12
    }
  ]
}

export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}
